//
//  photoViewController.m
//  movie
//
//  Created by 李丹阳 on 15/7/23.
//  Copyright (c) 2015年 李丹阳. All rights reserved.
//

#import "photoViewController.h"

@interface photoViewController ()

@end

@implementation photoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self _createCollection];
    [self _createNav];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(hiddenNav) name:@"hiddenNavigationBarNotification" object:nil];
    // Do any additional setup after loading the view.
}
- (void)hiddenNav{
    BOOL isHidden = self.navigationController.navigationBar.isHidden;
    [self.navigationController.navigationBar setHidden:!isHidden];
}

- (void)_createCollection{
    UICollectionViewFlowLayout* layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = self.view.frame.size;
    layout.minimumLineSpacing = 0;
    
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    photoView = [[photoCollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:layout];
    photoView.pagingEnabled = YES;
    [self.view addSubview:photoView];
    
}

- (void)setImageUrlArray:(NSArray *)imageUrlArray{
    _imageUrlArray = imageUrlArray;
    photoView.imageUrlArray = _imageUrlArray;

    NSIndexPath* path = [NSIndexPath indexPathForRow:_index inSection:0];
    [photoView scrollToItemAtIndexPath:path atScrollPosition:UICollectionViewScrollPositionLeft animated:YES ];
}

- (void)_createNav{
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancelAction)];
}

- (void)cancelAction{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
